package com.eugene.element;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.eugene.enums.EMaturity;
import com.eugene.enums.ETimeUnit;
import com.eugene.util.HibernateUtil;

public class CurveBucket {
	/**
	 * @uml.property  name="maturity"
	 * @uml.associationEnd  
	 */
	private EMaturity maturity;
	/**
	 * @uml.property  name="timeUnit"
	 * @uml.associationEnd  
	 */
	private ETimeUnit timeUnit;
	/**
	 * @uml.property  name="timeUnitNum"
	 */
	private int timeUnitNum;
	/**
	 * @uml.property  name="dayNum"
	 */
	private int dayNum;
	
	private static List<CurveBucket> curveBuckets;

	public CurveBucket(){
	}
	
	public CurveBucket(EMaturity mat, int timeUnitNum, ETimeUnit timeUnit){
		this.maturity = mat;
		this.timeUnitNum = timeUnitNum;
		this.timeUnit = timeUnit;
	}
	
	/**
	 * @return
	 * @uml.property  name="maturity"
	 */
	public EMaturity getMaturity() {
		return maturity;
	}

	/**
	 * @param maturity
	 * @uml.property  name="maturity"
	 */
	public void setMaturity(EMaturity maturity) {
		this.maturity = maturity;
	}

	/**
	 * @return
	 * @uml.property  name="timeUnit"
	 */
	public ETimeUnit getTimeUnit() {
		return timeUnit;
	}

	/**
	 * @param timeUnit
	 * @uml.property  name="timeUnit"
	 */
	public void setTimeUnit(ETimeUnit timeUnit) {
		this.timeUnit = timeUnit;
	}

	/**
	 * @return
	 * @uml.property  name="timeUnitNum"
	 */
	public int getTimeUnitNum() {
		return timeUnitNum;
	}

	/**
	 * @param timeUnitNum
	 * @uml.property  name="timeUnitNum"
	 */
	public void setTimeUnitNum(int timeUnitNum) {
		this.timeUnitNum = timeUnitNum;
	}
	/**
	 * @return
	 * @uml.property  name="dayNum"
	 */
	public int getDayNum() {
		return dayNum;
	}

	/**
	 * @param dayNum
	 * @uml.property  name="dayNum"
	 */
	public void setDayNum(int dayNum) {
		this.dayNum = dayNum;
	}

	public EMaturity getEMaturity(){
		for(EMaturity mat: EMaturity.values()){
			if( mat.Type==this.getTimeUnit().type 
					&& mat.num == this.getTimeUnitNum()){
				return mat;
			}
		}
		return EMaturity.MATURITY;
	}
/**
 * @param
 * @return Common Curve Buckets used to show IR Curve in the system. 
*/	
	public static List<CurveBucket> getCurveBuckets(){
		if (curveBuckets ==null){
			curveBuckets =new ArrayList<CurveBucket>();
			Session s = HibernateUtil.currentSession();
			Query qr =s.createQuery("from CurveBucket");
			curveBuckets=qr.list();
			
			return curveBuckets;
		}
		//System.out.println("call the exist reference");
		return curveBuckets;
	}
	
}
